1 package com.inigoserrano.isvalidator.alfa.examples;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.util.Enumeration;
6 import java.util.Hashtable;
7
8 import javax.servlet.ServletException;
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11
12 import com.inigoserrano.isvalidator.alfa.formModel.TextField;
13 import com.inigoserrano.isvalidator.check.DateCheck;
14 import com.inigoserrano.isvalidator.check.EmailCheck;
15 import com.inigoserrano.isvalidator.check.RegularExpresionCheck;
16 import com.inigoserrano.isvalidator.dataGroup.SimpleDataGroup;
17 import com.inigoserrano.isvalidator.errorDo.ErrorDo;
18 import com.inigoserrano.isvalidator.errorDo.ErrorDoGroup;
19 import com.inigoserrano.isvalidator.errorDo.SimpleErrorDo;
20 import com.inigoserrano.isvalidator.errorDo.SimpleErrorDoGroup;
21
22 /***
23 * Here the description of the class
24 *
25 * @license@
26 *
27 * @version @version@
28 * @author @author@
29 */
30 public class exampleServletForm extends javax.servlet.http.HttpServlet {
31 /***
32 * Here the documentation
33 */
34 public exampleServletForm() {
35 super();
36 }
37
38 /***
39 * Inserte aquí la descripción del método.
40 * Fecha de creación: (28/10/2001 18:43:03)
41 * @param form com.inigoserrano.isvalidator.dataGroup.SimpleMetaContainer
42 */
43 private void paintValidForm(SimpleDataGroup form) {
44 //form.
45 }
46 /***
47 * the service of the servlet
48 * @param req the request
49 * @param res the response
50 * @throws IOException IOException
51 * @throws ServletException ServletException
52 */
53 public void service(HttpServletRequest req, HttpServletResponse res)
54 throws ServletException, IOException {
55 PrintWriter out = res.getWriter();
56 res.setContentType("text/html");
57 try {
58 //For the email
59 TextField theEmail = new TextField("email", req);
60 theEmail.addCheck(new EmailCheck());
61 theEmail.addCheck(new RegularExpresionCheck(".{1,100}"));
62 //For the subject
63 TextField theSubject = new TextField("subject", req);
64 theSubject.addCheck(new RegularExpresionCheck(".{1,255}"));
65 //For the Date
66 TextField theDate = new TextField("date", req);
67 theDate.addCheck(new DateCheck());
68 //For the Body
69 TextField theBody = new TextField("body", req);
70 theBody.addCheck(new RegularExpresionCheck(".{1,1000}"));
71 //The meta container
72 SimpleDataGroup inputParameters = new SimpleDataGroup();
73 inputParameters.addData(theEmail);
74 inputParameters.addData(theSubject);
75 inputParameters.addData(theDate);
76 inputParameters.addData(theBody);
77 if (inputParameters.check()) {
78 out.println("All Ok");
79 out.println("The Email is: " + theEmail.getValueToCheck());
80 out.println("The Subject is: " + theSubject.getValueToCheck());
81 out.println("The Date is: " + theDate.getValueToCheck());
82 out.println("The Body is: " + theBody.getValueToCheck());
83 } else {
84 out.println("Not Ok");
85 Hashtable errorMessages = new Hashtable();
86 errorMessages.put(
87 "EmailConstraint",
88 "The argument ($valueToCheck;) is not a valid email");
89 errorMessages.put(
90 "RegularExpresionConstraint",
91 "The argument ($valueToCheck;) has an invalid size");
92 errorMessages.put(
93 "DateConstraint",
94 "The argument ($valueToCheck;) is not a valid date");
95 errorMessages.put(
96 "NotNullConstraint",
97 "You haven´t put all the parameters");
98 errorMessages.put(
99 "NotBlankConstraint",
100 "You have put a blank parameter");
101 inputParameters.setErrorDo(
102 new SimpleErrorDo(errorMessages),
103 new SimpleErrorDoGroup());
104 ErrorDoGroup errorContainer = inputParameters.getErrorDoGroup();
105 Enumeration iterator = errorContainer.elements();
106 while (iterator.hasMoreElements()) {
107 out.println(
108 ((ErrorDo) iterator.nextElement()).getMessage());
109 }
110 }
111 } catch (Exception e) {
112 e.printStackTrace(out);
113 }
114 }
115 }
This page was automatically generated by Maven